<template>
  <div>
    <el-table :data="tableDatas" style="width: 100%">
      <el-table-column type="expand">
        <template slot-scope="props" v-if="props.row.type!=1">
          <el-table border :data="props.row.discount" style="width: 100%">
            <el-table-column prop="name" label="活动"></el-table-column>
            <el-table-column prop="original_price" label="折扣"></el-table-column>
            <el-table-column prop="activity_price" label="折后价"></el-table-column>
            <el-table-column prop="create_time" label="活动时间"></el-table-column>
            <el-table-column prop="status" label="是否启用">
              <template slot-scope="scope">
                <!-- <img
                  v-if="scope.row.status==1"
                  src="../../../assets/img/dui.png"
                  style="width:14px;height:14px"
                  alt
                />
                <img v-else src="../../../assets/img/error.png" style="width:14px;height:14px" alt />-->
                <el-switch
                  v-model="scope.row.check"
                  @change="stoppentab2(scope.row)"
                  active-color="#409EFF"
                  inactive-color="#DCDFE6"
                ></el-switch>
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button type="text" v-if="sell_27" @click="edittab2(scope.row)">编辑</el-button>
                <!-- <el-button
                  type="text"
                  v-if="scope.row.status==1&&sell_29"
                  @click="stoppentab2(scope.row)"
                >停用</el-button>
                <el-button
                  type="text"
                  v-if="scope.row.status!=1&&sell_29"
                  @click="stoppentab2(scope.row)"
                >启用</el-button>-->
                <el-button type="text" v-if="sell_28" @click="deltab2(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div style="text-align:center;margin-top:10px">
            <!-- <template slot-scope="scope"> -->
            <el-button
              type="primary"
              size="mini"
              v-if="sell_20"
              @click="adddiscount(props.row)"
            >添加折扣活动</el-button>
            <!-- </template> -->
          </div>
        </template>
      </el-table-column>
      <el-table-column label="套餐名" prop="title"></el-table-column>
      <el-table-column label="套餐类型" prop="type">
        <template slot-scope="scopes">
          <span v-if="scopes.row.type==1">次卡</span>
          <span v-if="scopes.row.type==2">期卡</span>
          <span v-if="scopes.row.type==3">小时卡</span>
        </template>
      </el-table-column>
      <el-table-column label="适用类别" prop="genre" show-overflow-tooltip>
        <template slot-scope="scope">
          <a
            size="mini"
            style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"
            v-for="(item,index) in scope.row.genre"
            :key="index"
          >{{scope.row.genre.length==1?item.title:item.title+","}}</a>
        </template>
      </el-table-column>
      <el-table-column label="适用门店" prop="name.store_name" show-overflow-tooltip>
        <template slot-scope="scope">
          <!-- <el-button size="mini" style="display:inline-block;margin-bottom:10px;" v-for="(item,index) in scope.row.name" :key="index">{{item.store_name}}</el-button> -->
          <a
            size="mini"
            style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;"
            v-for="(item,index) in scope.row.name"
            :key="index"
          >{{scope.row.name.length==1?item.store_name:item.store_name+","}}</a>
        </template>
      </el-table-column>
      <el-table-column label="适用时间段" width="300" prop="time_slot_state">
        <template slot-scope="scope">
          <div
            v-if="scope.row.time_slot_state==1"
          >工作日：{{scope.row.start_time}}-{{scope.row.end_time}}</div>
          <div
            v-if="scope.row.time_slot_state==2"
          >周末：{{scope.row.holidays_start_time}}-{{scope.row.holidays_end_time}}</div>
          <div v-if="scope.row.time_slot_state==3">
            <div>工作日：{{scope.row.start_time}}-{{scope.row.end_time}}</div>
            <div>周末：{{scope.row.holidays_start_time}}-{{scope.row.holidays_end_time}}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="费用" prop="cost"></el-table-column>
      <el-table-column label="顺序权重" prop="sort"></el-table-column>
      <el-table-column label="启用" prop="enable">
        <template slot-scope="scope">
          <!-- <img
            src="../../../assets/img/dui.png"
            v-if="scope.row.status==1"
            style="width:14px;height:14px"
            alt
          />
          <img src="../../../assets/img/error.png" v-else style="width:14px;height:14px" alt />-->
          <el-switch
            v-model="scope.row.check"
            @change="openprop(scope.row)"
            active-color="#409EFF"
            inactive-color="#DCDFE6"
          ></el-switch>
        </template>
      </el-table-column>
      <!-- <el-table-column label="显示" prop="display">
        <template slot-scope="scope">
          <img
            src="../../../assets/img/dui.png"
            v-if="scope.row.show==1"
            style="width:14px;height:14px"
            alt
          />
          <img src="../../../assets/img/error.png" v-else style="width:14px;height:14px" alt />
        </template>
      </el-table-column>-->
      <el-table-column label="操作" width="250">
        <template slot-scope="scord">
          <el-button type="text" v-if="sell_21" @click="editcli(scord.row)">编辑</el-button>
          <!-- <el-button type="text" v-if="scord.row.status==1&&sell_22" @click="openprop(scord.row)">停用</el-button> -->
          <!-- <el-button type="text" v-if="scord.row.status!=1&&sell_22" @click="openprop(scord.row)">启用</el-button> -->
          <!-- <el-button type="text" v-if="scord.row.show==1&&sell_23" @click="showprop(scord.row)">隐藏</el-button>
          <el-button type="text" v-if="scord.row.show!=1&&sell_23" @click="showprop(scord.row)">显示</el-button>-->
          <el-button type="text" v-if="sell_25" @click="setsort(scord.row)">排序</el-button>
          <el-button type="text" v-if="sell_24" @click="del(scord.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="width:100%;text-align:center;margin:50px auto;">
      <el-pagination
        background
        :page-size="10"
        :page-sizes="[10, 20, 50, 100]"
        layout="total,prev, sizes, pager, next, jumper"
        :total="totle"
        @size-change="handleSizeChange"
        @current-change="fenyeBtn"
      ></el-pagination>
    </div>
    <el-dialog title="套餐排序" :visible.sync="sortpopup" width="50%">
      <el-form ref="formInfo" :model="formInfo" class="demo-form-inline" label-width="100px">
        <el-form-item label="门店" prop="shop" label-width="100px">
          <span>{{formInfo.title}}</span>
        </el-form-item>
        <el-form-item label="日期" prop="date" label-width="100px">
          <!-- <el-input v-model="formInfo.date" placeholder="请输入日期" /> -->
          <el-date-picker
            v-model="formInfo.date"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="选择日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="排序" prop="sort" label-width="100px">
          <el-input v-model="formInfo.sort" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="说明" prop="say" label-width="100px">
          <span>{{formInfo.say}}</span>
        </el-form-item>
        <el-form-item style="text-align: right;">
          <el-button @click="sortpopup=false">取消</el-button>
          <el-button type="primary" @click="submitForm('formInfo')">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="添加折扣活动" :visible.sync="discountpopup" width="50%">
      <el-form
        ref="discountformInfo"
        :model="discountformInfo"
        class="demo-form-inline"
        label-width="100px"
        :rules="rules"
      >
        <el-form-item label="活动名" prop="name" label-width="100px">
          <el-input v-model="discountformInfo.name" placeholder="请输入活动名" />
        </el-form-item>
        <el-form-item label="原价" prop="price" label-width="100px">
          <span>{{discountformInfo.price}}</span>
        </el-form-item>
        <el-form-item label="活动价" prop="activityprice" label-width="100px">
          <el-input v-model="discountformInfo.activityprice" placeholder="请输入活动价">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="活动日期" prop="value1" label-width="100px">
          <el-date-picker
            v-model="discountformInfo.value1"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item style="text-align: right;">
          <el-button @click="discountpopup=false">取消</el-button>
          <el-button type="primary" @click="submitFormdiscount('discountformInfo')">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="编辑折扣活动" :visible.sync="editdiscountpopup" width="50%">
      <el-form
        ref="editdiscountformInfo"
        :model="editdiscountformInfo"
        class="demo-form-inline"
        label-width="100px"
        :rules="rules"
      >
        <el-form-item label="活动名" prop="name" label-width="100px">
          <el-input v-model="editdiscountformInfo.name" placeholder="请输入活动名" />
        </el-form-item>
        <el-form-item label="原价" prop="original_price" label-width="100px">
          <span>{{editdiscountformInfo.original_price}}</span>
        </el-form-item>
        <el-form-item label="活动价" prop="activity_price" label-width="100px">
          <el-input v-model="editdiscountformInfo.activity_price" placeholder="请输入活动价">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="活动日期" prop="time" label-width="100px">
          <el-date-picker
            v-model="editdiscountformInfo.time"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item style="text-align: right;">
          <el-button @click="editdiscountpopup=false">取消</el-button>
          <el-button type="primary" @click="submitFormeditdiscount('editdiscountformInfo')">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog title="编辑套餐" :visible.sync="editmealpopup" @close="closepopup" width="50%">
      <el-form
        ref="editmealformInfo"
        :model="editmealformInfo"
        class="demo-form-inline"
        label-width="100px"
        :rules="rules"
      >
        <el-form-item label="套餐标题" prop="title" label-width="100px">
          <el-input v-model="editmealformInfo.title" placeholder="请输入套餐标题" />
        </el-form-item>
        <el-form-item label="套餐类型" prop="type">
          <el-select
            v-model="editmealformInfo.type"
            style="width:50%"
            @change="chagemeal"
            disabled
            placeholder="请选择套餐类型"
          >
            <el-option v-for="item in cardtype" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <div style="text-align:center;width:98%;margin-left:20px">
          <el-divider>使用条件</el-divider>
        </div>
        <el-form-item v-if="changeval==1" label="最长可使用" prop="hour">
          <el-input v-model="editmealformInfo.hour" style="width:98%">
            <template slot="append">小时</template>
          </el-input>
        </el-form-item>
        <el-form-item v-if="changeval==1" label="可使用次数" prop="frequency">
          <el-input v-model="editmealformInfo.frequency" style="width:98%">
            <template slot="append">次</template>
          </el-input>
        </el-form-item>
        <!-- <el-form-item
          v-if="changeval==2"
          label="套餐天数"
          prop="day"
        >
          <el-input v-model="editmealformInfo.day" style="width:98%">
            <template slot="append">天</template>
          </el-input>
        </el-form-item>-->
        <!-- <el-form-item v-if="changeval==2" label="激活方式" prop="activation">
          <el-radio-group v-model="editmealformInfo.activation" @change="changeradio">
            <el-radio v-for="(item,index) in itemradio" :key="index" :label="item.id">{{item.name}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="radiobool=='3'" label="生效日期" prop="take_effect">
          <el-date-picker
            value-format="yyyy-MM-dd"
            v-model="value1"
            type="date"
            placeholder="选择日期"
          ></el-date-picker>
        </el-form-item>-->
        <el-form-item v-if="changeval==3" label="可用总小时数" prop="count_hour">
          <el-input v-model="editmealformInfo.count_hour" style="width:98%">
            <template slot="append">小时</template>
          </el-input>
        </el-form-item>
        <el-form-item label="有效期" v-if="changeval==3||changeval==2" prop="day">
          <el-input v-model="editmealformInfo.day" style="width:98%">
            <template slot="append">天</template>
          </el-input>
          <div v-if="changeval==2">有效期不能为0</div>
          <div v-if="changeval==3">有效期为0时则不限制</div>
        </el-form-item>
        <el-form-item v-if="changeval!=''" label="字体颜色选择" prop="color">
          <!-- <el-input v-model="editmealformInfo.color" style="width:98%">
          </el-input>-->
          <div style="display:flex;">
            <el-input v-model="editmealformInfo.color" style="width:98%"></el-input>
            <el-color-picker @change="changecolor" v-model="editmealformInfo.color"></el-color-picker>
          </div>
        </el-form-item>
        <el-form-item v-if="changeval!=''" label="背景颜色选择" prop="background">
          <div style="display:flex;">
            <el-input v-model="editmealformInfo.background" style="width:98%"></el-input>
            <el-color-picker @change="changecolors" v-model="editmealformInfo.background"></el-color-picker>
          </div>
        </el-form-item>
        <div v-if="changeval==3||changeval==1" style="display:flex;align-items: flex-start">
          <div
            style="display:flex;width:100%;align-items: flex-start;justify-content: flex-start;flex-direction: column;"
          >
            <!-- <div class="flexwap" v-if="editmealformInfo.days_price.length!=0">
              <el-form-item label="天数" prop="day">
                <el-input v-model="editmealformInfo.day">
                  <template slot="append">天</template>
                </el-input>
              </el-form-item>
              <el-form-item label="价格" prop="days_price">
                <el-input v-model="editmealformInfo.days_price">
                  <template slot="append">元</template>
                </el-input>
              </el-form-item>
              <el-button @click="addDomain" style="margin-left:40px" type="text">添加</el-button>
            </div>-->
            <div class="flexwap" v-for="(domain,index) in editmealformInfo.days_price" :key="index">
              <el-form-item label="天数">
                <el-input v-model="domain.day" oninput="value=value.replace(/[^\d.]/g, '').replace(/^0{1}/g,'')">
                  <template slot="append">天</template>
                </el-input>
              </el-form-item>
              <el-form-item label="价格">
                <el-input v-model="domain.price" oninput="value=value.replace(/[^\d.]/g, '').replace(/^0{1}/g,'')">
                  <template slot="append">元</template>
                </el-input>
              </el-form-item>
              <el-button
                v-if="index==0"
                @click.prevent="addDomain"
                style="margin-left:40px"
                type="text"
              >添加</el-button>
              <el-button
                v-else
                @click.prevent="removeDomain(domain)"
                style="margin-left:40px"
                type="text"
              >删除</el-button>
            </div>
            <div v-if="tips" style="color:#FF2222;font-size:12px;margin-left:60px">提示：最多添加四个</div>
          </div>
        </div>
        <div style="text-align:center;width:98%;margin-left:20px">
          <el-divider>可预约时间段</el-divider>
        </div>
        <div style="color:#333333;font-size:14px;margin-bottom:24px;margin-left:20px">工作日和周末至少选择一个</div>
        <div style="margin-left:20px">
          <div style="margin-bottom:14px;display:flex;width:100%">
            <el-checkbox v-model="check1" @change="clichecked1" label="工作日" border></el-checkbox>
            <div v-if="check1" style="margin-left:18px">
              <el-time-picker
              is-range
              v-model="startTime1"
              format="HH:mm"
              value-format="HH:mm"
              @change="changetabs"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              placeholder="选择时间范围">
            </el-time-picker>
              <!-- <el-time-select
                placeholder="开始时间"
                v-model="editmealformInfo.start_time"
                :picker-options="{start: '00:00',step: '00:30',end: '24:00',maxTime: editmealformInfo.end_time}"
              ></el-time-select>
              <span class="line" :span="1">-</span>
              <el-time-select
                placeholder="结束时间"
                v-model="editmealformInfo.end_time"
                :picker-options="{start: '00:00',step: '00:30',end: '24:00',minTime: editmealformInfo.start_time}"
              ></el-time-select> -->
            </div>
          </div>
          <div style="margin-bottom:42px;display:flex;width:100%">
            <el-checkbox v-model="check2" @change="clichecked2" label="周末" border></el-checkbox>
            <div v-if="check2" style="margin-left:18px">
              <el-time-picker
              is-range
              v-model="startTime2"
              format="HH:mm"
              value-format="HH:mm"
              @change="changetaps"
              range-separator="至"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
              placeholder="选择时间范围">
            </el-time-picker>
              <!-- <el-time-select
                placeholder="开始时间"
                v-model="editmealformInfo.holidays_start_time"
                :picker-options="{start: '00:00',step: '00:30',end: '24:00',maxTime: editmealformInfo.holidays_end_time}"
              ></el-time-select>
              <span class="line">-</span>
              <el-time-select
                placeholder="结束时间"
                v-model="editmealformInfo.holidays_end_time"
                :picker-options="{start: '00:00',step: '00:30',end: '24:00',minTime: editmealformInfo.holidays_start_time}"
              ></el-time-select> -->
            </div>
          </div>
        </div>
        <div style="text-align:center;width:98%;margin-left:20px">
          <el-divider></el-divider>
        </div>
        <el-form-item label="适用门店" prop="name">
          <el-select
            v-model="editmealformInfo.store_ids"
            @change="$forceUpdate()"
            style="width:50%"
            multiple
            placeholder="请选择"
          >
            <el-option
              v-for="(item,index) in storelist"
              :key="index"
              :label="item.store_name"
              :value="item.id"
            ></el-option>
            <!-- <el-option label="银点" value="2"></el-option>
            <el-option label="通电" value="3"></el-option>-->
          </el-select>
        </el-form-item>
        <el-form-item label="适用座位类型" prop="genre">
          <el-select
            v-model="editmealformInfo.seat_type_id"
            @change="$forceUpdate()"
            style="width:50%"
            multiple
            placeholder="请选择"
          >
            <el-option
              :label="item.title"
              v-for="(item,index) in genrelist"
              :key="index"
              :value="item.id"
            ></el-option>
            <!-- <el-option label="商务座" value="2"></el-option>
            <el-option label="豪华座" value="3"></el-option>-->
          </el-select>
        </el-form-item>
        <el-form-item label="限制购买次数" prop="limit">
          <el-input v-model="editmealformInfo.limit" style="width:98%">
            <template slot="append">次</template>
          </el-input>
          <div>设置次数为0时则不为限制购买</div>
        </el-form-item>
        <el-form-item label="套餐费用" prop="cost">
          <el-input v-model="editmealformInfo.cost" style="width:98%">
            <template slot="append">元</template>
          </el-input>
          <div>费用为0时则用户注册后马上获得该套餐，仅最近的一个可生效</div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submiteditForm('editmealformInfo')">修改</el-button>
          <el-button @click="resetForm('editmealformInfo')">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import {
  setMeal,
  setMealSort,
  setMealDeactivate,
  setMealShow,
  setMealDelete,
  lists,
  setDiscount,
  activityEdit,
  activityDel,
  activityStop,
  setMealEdit,
  setReturn
} from "@/api/user";
import Base64 from "@/utils/base";
import { getp_id } from "@/utils/getmenuid";
var moment = require("moment");
export default {
  inject:['reload'],
  data() {
    return {
      totle: 10,
      page: 1,
      num: 10,
      tips: false,
      sell_20: false,
      sell_21: false,
      sell_22: false,
      sell_23: false,
      sell_24: false,
      sell_25: false,
      sell_27: false,
      sell_28: false,
      sell_29: false,
      check1: false,
      check2: false,
      changeval: "",
      // radiobool: "",
      startTime1: [],
      startTime2: [],
      startTime: "",
      endTime: "",
      startTimes: "",
      endTimes: "",
      cardtype: [
        {
          id: 3,
          name: "小时卡"
        },
        {
          id: 1,
          name: "次卡"
        },
        {
          id: 2,
          name: "期卡"
        }
      ],
      discountformInfoid: "",
      formInfo: {
        shop: ""
        // date: "2022-12-12"
      },
      editmealformInfo: "",
      // value1:"",
      discountformInfo: {
        value1: "",
        price: "",
        name: "",
        activityprice: ""
      },
      editdiscountformInfo: {
        time: []
      },
      itemradio: [
        {
          id: 1,
          name: "首次使用"
        },
        {
          id: 2,
          name: "立即"
        },
        {
          id: 3,
          name: "设置生效日期"
        }
      ],
      editdiscountformInfoid: "",
      sortpopup: false,
      discountpopup: false,
      genrelist: "",
      storelist: "",
      editdiscountpopup: false,
      editmealpopup: false,
      rules: {
        name: [{ required: true, message: "请输入活动名称", trigger: "blur" }],
        activityprice: [
          { required: true, message: "请输入活动价格", trigger: "blur" }
        ],
        value1: [{ required: true, message: "请输入活动日期", trigger: "blur" }]
      },
      tableDatas: ""
    };
  },
  created() {
    this.getlists();
    setTimeout(() => {
      // this.getsetMeal(1);
      this.getolddata()
    }, 500);
  },
  methods: {
        // 中国标准时间 转换成 年月日
 getSimpleDate(date) {
  var y = date.getFullYear();
  var m = date.getMonth() + 1;
  m = m < 10 ? ('0' + m) : m;
  var d = date.getDate();
  d = d < 10 ? ('0' + d) : d;
  var h = date.getHours();
  var minute = date.getMinutes();
  minute = minute < 10 ? ('0' + minute) : minute;
  var s = date.getSeconds();
  s = s < 10 ? '0' + s : s;
  return h + ':' + minute
},
    changetabs(e){
        this.startTime1[0] = this.getSimpleDate(e[0])
        this.startTime1[1] = this.getSimpleDate(e[1])
    },
    changetaps(e){
        this.startTime2[0] = this.getSimpleDate(e[0])
        this.startTime2[1] = this.getSimpleDate(e[1])
    },
    getolddata(){
      this.tableDatas = JSON.parse(localStorage.getItem("tableDatas"))
      this.totle = JSON.parse(localStorage.getItem("totle"))
    },
    getlists() {
      lists({
        request_data: Base64.encode(JSON.stringify({ pid: getp_id() }))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        let btnarr = [];
        res.result.map(v => {
          btnarr.push(v.class_mark);
        });
        btnarr.forEach(item => {
          if (item == "sell_20") {
            this.sell_20 = true;
          }
          if (item == "sell_21") {
            this.sell_21 = true;
          }
          if (item == "sell_22") {
            this.sell_22 = true;
          }
          if (item == "sell_23") {
            this.sell_23 = true;
          }
          if (item == "sell_24") {
            this.sell_24 = true;
          }
          if (item == "sell_25") {
            this.sell_25 = true;
          }
          if (item == "sell_27") {
            this.sell_27 = true;
          }
          if (item == "sell_28") {
            this.sell_28 = true;
          }
          if (item == "sell_29") {
            this.sell_29 = true;
          }
        });
      });
    },
    chagemeal(e) {
      this.changeval = e;
    },
    addDomain() {
      if (this.editmealformInfo.days_price.length > 3) {
        this.tips = true;
        return false;
      }
      this.editmealformInfo.days_price.push({});
      // this.$nextTick(() => {
      //   this.$refs.editmealformInfo
      // });
    },
    removeDomain(item) {
      var index = this.editmealformInfo.days_price.indexOf(item);
      if (index !== -1) {
        this.editmealformInfo.days_price.splice(index, 1);
      }
      if (this.editmealformInfo.days_price.length < 3) {
        this.tips = false;
      }
    },
    editcli(data) {
      this.check1 = false;
      this.check2 = false;
      if (data.time_slot_state == 1) {
        this.check1 = true;
        // this.$set(this.startTime1, "0", moment(data.start_time).format('HH:mm'))
        // this.$set(this.startTime1, "1", moment(data.end_time).format('HH:mm'))
        this.startTime1[0] = data.start_time
        this.startTime1[1] = data.end_time
      }
      if (data.time_slot_state == 2) {
        this.check2 = true;
        // this.$set(this.startTime2, "0", moment(data.holidays_start_time).format('HH:mm'))
        // this.$set(this.startTime2, "1", moment(data.holidays_end_time).format('HH:mm'))
        this.startTime2[0] = data.holidays_start_time
        this.startTime2[1] = data.holidays_end_time
      }
      if (data.time_slot_state == 3) {
        this.check1 = true;
        this.check2 = true;
        // this.$set(this.startTime1, "0", moment(data.start_time).format('HH:mm'))
        // this.$set(this.startTime1, "1", moment(data.end_time).format('HH:mm'))
        // this.$set(this.startTime2, "0", moment(data.holidays_start_time).format('HH:mm'))
        // this.$set(this.startTime2, "1", moment(data.holidays_end_time).format('HH:mm'))
        this.startTime1[0] = data.start_time
        this.startTime1[1] = data.end_time
        this.startTime2[0] = data.holidays_start_time
        this.startTime2[1] = data.holidays_end_time
      }
      this.editmealformInfo = data;
      this.changeval = data.type;
      this.adminid = data.id;
      // this.radiobool = data.activation;
      this.changeval = data.type;
      //下拉数据
      setReturn({}).then(res => {
         if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.genrelist = res.result.genre;
        this.storelist = res.result.store;
        let storeid = [];
        let genreid = [];
        data.name.map(i => {
          storeid.push(i.id);
        });
        data.genre.map(i => {
          genreid.push(i.id);
        });
        this.editmealformInfo.store_ids = storeid;
        this.editmealformInfo.seat_type_id = genreid;
        // this.editmealformInfo.domains = [];
        this.editmealpopup = true;
        // this.storemenu = res.data;
      });
    },
    openprop(val) {
      let parmes = {
        id: val.id,
        status: val.status == 1 ? 2 : 1
      };
      setMealDeactivate({
        request_data: Base64.encode(JSON.stringify(parmes))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.getsetMeal();
      });
    },
    changecolor(e) {
      this.editmealformInfo.color = e;
    },
    changecolors(e) {
      this.editmealformInfo.background = e;
    },
    showprop(val) {
      let parmes = {
        id: val.id,
        show: val.show == 1 ? 2 : 1
      };
      setMealShow({
        request_data: Base64.encode(JSON.stringify(parmes))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.getsetMeal();
      });
    },
    stoppentab2(val) {
      activityStop({
        request_data: Base64.encode(JSON.stringify({ id: val.id }))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.getsetMeal();
      });
    },
    edittab2(val) {
      this.editdiscountpopup = true;
      this.editdiscountformInfoid = val.set_id;
      this.editdiscountformInfo = JSON.parse(JSON.stringify(val));
      this.$set(this.editdiscountformInfo, "time", [
        moment(val.start_time * 1000).format("YYYY-MM-DD"),
        moment(val.end_time * 1000).format("YYYY-MM-DD")
      ]);
    },
    deltab2(val) {
      this.$confirm("确定删除此条数据吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          activityDel({
            request_data: Base64.encode(JSON.stringify({ id: val.id }))
          }).then(res => {
            if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
            this.getsetMeal();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    closepopup(){
      this.reload()
    },
    //删除
    del(id) {
      this.$confirm("确定删除此条数据吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let parmes = {
            id: id
          };
          setMealDelete({
            request_data: Base64.encode(JSON.stringify(parmes))
          }).then(res => {
            if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
            this.getsetMeal();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    handleSizeChange(val) {
      this.num = val;
      this.getsetMeal(this.page, this.num);
    },
    fenyeBtn(e) {
      this.page = e;
      this.getsetMeal(this.page, this.num);
    },
    getsetMeal(page, num) {
      let parmes = {
        store_ids:localStorage.getItem("shop_id"),
        type:localStorage.getItem("type_id"),
        page: page || this.page,
        limit: num || this.num
      };
      setMeal({
        request_data: Base64.encode(JSON.stringify(parmes))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.tableDatas = res.result.data;
        this.totle = res.result.count;
      });
    },
    clichecked1(e) {
      this.check1 = e;
      if (e == false) {
        this.editmealformInfo.start_time = "";
        this.editmealformInfo.end_time = "";
      }
    },
    clichecked2(e) {
      this.check2 = e;
      if (e == false) {
        this.editmealformInfo.holidays_start_time = "";
        this.editmealformInfo.holidays_end_time = "";
      }
    },
    setsort(val) {
      val["say"] = "按照权重由小到大在小程序显示顺序";
      this.formInfo = JSON.parse(JSON.stringify(val));
      this.sortpopup = true;
    },
    submitForm() {
      let parmes = {
        id: this.formInfo.id,
        sort: this.formInfo.sort
      };
      setMealSort({
        request_data: Base64.encode(JSON.stringify(parmes))
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.sortpopup = false;
        this.getsetMeal();
      });
    },
    submiteditForm(editmealformInfo) {
      if (this.editmealformInfo.title == "") {
        this.$message({
          message: "请输入套餐名称",
          type: "warning"
        });
        return;
      }
      if (this.editmealformInfo.count_hour == "" && this.changeval == 3) {
        this.$message({
          message: "请输入可用总小时数",
          type: "warning"
        });
        return;
      }
      if (this.editmealformInfo.day == "" && this.changeval == 3) {
        this.$message({
          message: "请输入有效期",
          type: "warning"
        });
        return;
      }
      if (this.editmealformInfo.day == "0" && this.changeval == 2) {
        this.$message({
          message: "有效期需大于0",
          type: "warning"
        });
        return;
      }
      if (this.editmealformInfo.color == "") {
        this.$message({
          message: "请选择字体颜色",
          type: "warning"
        });
        return;
      }
      if (this.editmealformInfo.background == "") {
        this.$message({
          message: "请选择背景颜色",
          type: "warning"
        });
        return;
      }
      if (this.check1 == false && this.check2 == false) {
        this.$message({
          message: "工作日和周末至少选择一个",
          type: "warning"
        });
        return;
      }
      if(this.check1==true){
         if(this.startTime1 == null){
        this.$message({
          message:"请选择工作日时间段",
          type: "warning"
        })
        return
      }
      // if(this.startTime1[1]==null){
      //   this.$message({
      //     message:"请选择结束时间",
      //     type: "warning"
      //   })
      //   return
      // }
      }
      if(this.check2==true){
         if(this.startTime2==null){
        this.$message({
          message:"请选择周末时间段",
          type: "warning"
        })
        return
      }
      // if(this.startTime2==null){
      //   this.$message({
      //     message:"请选择结束时间",
      //     type: "warning"
      //   })
      //   return
      // }
      }
      let params = {
        id: this.editmealformInfo.id,
        title: this.editmealformInfo.title,
        type: this.changeval,
        color: this.editmealformInfo.color,
        background: this.editmealformInfo.background,
        time_slot_state:
          this.check1 && this.check2
            ? 3
            : this.check1
            ? 1
            : this.check2
            ? 2
            : "",
        start_time: this.startTime1[0] || "",
        end_time: this.startTime1[1] || "",
        holidays_start_time: this.startTime2[0] || "",
        holidays_end_time: this.startTime2[1] || "",
        frequency: this.editmealformInfo.frequency,
        limit: this.editmealformInfo.limit,
        seat_type_id: this.editmealformInfo.seat_type_id.join(","),
        cost: this.editmealformInfo.cost,
        store_ids: this.editmealformInfo.store_ids.join(","),
        hour: this.changeval == 1 ? this.editmealformInfo.hour : 0,
        count_hour: this.changeval == 3 ? this.editmealformInfo.count_hour : 0,
        day:
          this.changeval == 3 || this.changeval == 2
            ? this.editmealformInfo.day
            : 0,
        days_price: this.editmealformInfo.days_price,
        activation: 2
        // take_effect: this.value1 || ""
      };
      this.$refs[editmealformInfo].validate(valid => {
        if (valid) {
          setMealEdit({
            request_data: Base64.encode(JSON.stringify(params))
          }).then(res => {
            if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
            this.editmealpopup = false;
            this.$message({
              message: res.message,
              type: "success"
            });
            this.getsetMeal();
          });
        } else {
          return false;
        }
      });
    },
    submitFormdiscount(discountformInfo) {
      this.$refs[discountformInfo].validate(valid => {
        if (valid) {
          setDiscount({
            request_data: Base64.encode(
              JSON.stringify({
                set_id: this.discountformInfoid,
                name: this.discountformInfo.name,
                original_price: this.discountformInfo.price,
                activity_price: this.discountformInfo.activityprice,
                start_time: this.discountformInfo.value1[0],
                end_time: this.discountformInfo.value1[1]
              })
            )
          }).then(res => {
            if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
            this.discountpopup = false;
            this.getsetMeal();
          });
        } else {
          return false;
        }
      });
    },
    submitFormeditdiscount(editdiscountformInfo) {
      // this.$refs[editdiscountformInfo].validate(valid => {
      //   if (valid) {
      setDiscount({
        request_data: Base64.encode(
          JSON.stringify({
            z_id: this.editdiscountformInfo.id,
            set_id: this.editdiscountformInfoid,
            name: this.editdiscountformInfo.name,
            original_price: this.editdiscountformInfo.original_price,
            activity_price: this.editdiscountformInfo.activity_price,
            start_time: moment(this.editdiscountformInfo.time[0]).format(
              "YYYY-MM-DD"
            ),
            end_time: moment(this.editdiscountformInfo.time[1]).format(
              "YYYY-MM-DD"
            )
          })
        )
      }).then(res => {
        if(res.status==2){
          this.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
        this.editdiscountpopup = false;
        this.getsetMeal();
      });
      //   } else {
      //     return false;
      //   }
      // });
    },
    resetForm(editmealformInfo) {
      this.editmealpopup = false;
    },
    adddiscount(val) {
      this.discountformInfo.price = val.cost;
      this.discountformInfoid = val.id;
      this.discountpopup = true;
    }
    // changeradio(e) {
    //   this.radiobool = e;
    // }
  }
};
</script>
<style scoped>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
.el-table__expanded-cell {
  background: #f5f5f5;
}
.flexwap {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
</style>